/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package ec.edu.espe.distribuidas.aseguradora.dao;

import ec.edu.espe.distribuidas.aseguradora.modelo.Siniestro;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author alejandro
 */
@Stateless
public class SiniestroFacade extends AbstractFacade<Siniestro>  {
    @PersistenceContext(unitName = "ec.edu.espe.distribuidas.aseguradora_AseguradoraJSF-ejb_ejb_1PU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public SiniestroFacade() {
        super(Siniestro.class);
    }
        public Siniestro findPorCodigo(String codigo)
    {
        Query qry=this.getEntityManager().createQuery("SELECT obj FROM Siniestro obj WHERE obj.codSiniestro="+codigo);
        return (Siniestro)qry.getResultList().get(0);
    }
     public List<Siniestro> findCreados()
    {
        Query qry=this.getEntityManager().createQuery("SELECT obj FROM Siniestro obj WHERE obj.estadoReclamo='Creado'");
        return qry.getResultList();
    }
    public List<Siniestro> findPendientes()
    {
        Query qry=this.getEntityManager().createQuery("SELECT obj FROM Siniestro obj WHERE obj.estadoReclamo='Pendiente'");
        return qry.getResultList();
    }
    public List<Siniestro> findCorreccion()
    {
        Query qry=this.getEntityManager().createQuery("SELECT obj FROM Siniestro obj WHERE obj.estadoReclamo='Correccion'");
        return qry.getResultList();
    }
    public List<Siniestro> findAprobado()
    {
        Query qry=this.getEntityManager().createQuery("SELECT obj FROM Siniestro obj WHERE obj.estadoReclamo='Aprobado'");
        return qry.getResultList();
    }
    
}
